package view;

import java.awt.Color;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.Locale;
import java.util.Map;
import javax.swing.table.DefaultTableModel;
import model.Candidato;
import model.Cargo;
import model.Voto;

public class Apuracao extends javax.swing.JDialog {

  //
  ArrayList<Cargo> cargos = Cargo.getAllCargos();
  DecimalFormat df = new DecimalFormat();
  //

  public Apuracao(java.awt.Frame parent, boolean modal) {
    super(parent, modal);
    initComponents();
    setLocationRelativeTo(null);
    iniciarTela();
    df.applyPattern("##.##");
    df.setMinimumFractionDigits(2);
    tableCandidatos.getTableHeader().setBackground(new Color(36,2,27));
    tableCandidatos.getTableHeader().setFont(new java.awt.Font("Segoe UI", 0, 18));
    tableCandidatos.getTableHeader().setForeground(Color.WHITE);
    jScrollPane1.getViewport().setBackground(new Color(0,153,153));    
    
    
  }

  @SuppressWarnings("unchecked")
  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
  private void initComponents() {

    jPanel5 = new javax.swing.JPanel();
    pnlMain = new javax.swing.JPanel();
    pnlTop = new javax.swing.JPanel();
    pnlTitulo = new javax.swing.JPanel();
    jLabel1 = new javax.swing.JLabel();
    pnlSelecaoCargo = new javax.swing.JPanel();
    jLabel2 = new javax.swing.JLabel();
    cbxSelecaoCargo = new javax.swing.JComboBox();
    pnlCenter = new javax.swing.JPanel();
    pnlVotacaoTop = new javax.swing.JPanel();
    lblTituloCargo = new javax.swing.JLabel();
    pnlVotacaoLeft = new javax.swing.JPanel();
    pnlVotos = new javax.swing.JPanel();
    jLabel3 = new javax.swing.JLabel();
    lblTotalVotos = new javax.swing.JLabel();
    pnlDetalheVotos = new javax.swing.JPanel();
    jLabel4 = new javax.swing.JLabel();
    pnlInfoVotosBrancos = new javax.swing.JPanel();
    lblQntdBrancos = new javax.swing.JLabel();
    lblPercentBrancos = new javax.swing.JLabel();
    jLabel7 = new javax.swing.JLabel();
    pnlInfoVotosNulos = new javax.swing.JPanel();
    lblQntdNulos = new javax.swing.JLabel();
    lblPercentNulos = new javax.swing.JLabel();
    jLabel5 = new javax.swing.JLabel();
    pnlInfoVotosValidos = new javax.swing.JPanel();
    lblQntdValidos = new javax.swing.JLabel();
    lblPercentValidos = new javax.swing.JLabel();
    pnlVotacaoButton = new javax.swing.JPanel();
    pnlVotacaoCenter = new javax.swing.JPanel();
    jScrollPane1 = new javax.swing.JScrollPane();
    tableCandidatos = new javax.swing.JTable();
    pnlVotacaoRight = new javax.swing.JPanel();
    pnlButton = new javax.swing.JPanel();
    lblStatus = new javax.swing.JLabel();

    javax.swing.GroupLayout jPanel5Layout = new javax.swing.GroupLayout(jPanel5);
    jPanel5.setLayout(jPanel5Layout);
    jPanel5Layout.setHorizontalGroup(
      jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addGap(0, 100, Short.MAX_VALUE)
    );
    jPanel5Layout.setVerticalGroup(
      jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addGap(0, 100, Short.MAX_VALUE)
    );

    setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
    setMaximumSize(new java.awt.Dimension(1200, 600));
    setMinimumSize(new java.awt.Dimension(1200, 600));
    setPreferredSize(new java.awt.Dimension(1200, 600));
    getContentPane().setLayout(new java.awt.CardLayout());

    pnlMain.setBackground(new java.awt.Color(0, 51, 51));
    pnlMain.setLayout(new java.awt.BorderLayout());

    pnlTop.setBackground(new java.awt.Color(0, 51, 51));
    pnlTop.setMaximumSize(new java.awt.Dimension(100, 100));
    pnlTop.setMinimumSize(new java.awt.Dimension(80, 80));
    pnlTop.setPreferredSize(new java.awt.Dimension(80, 80));
    pnlTop.setLayout(new java.awt.GridLayout(2, 0));

    pnlTitulo.setBackground(new java.awt.Color(0, 51, 51));
    pnlTitulo.setLayout(new java.awt.CardLayout());

    jLabel1.setFont(new java.awt.Font("Segoe UI", 0, 18)); // NOI18N
    jLabel1.setForeground(new java.awt.Color(255, 255, 255));
    jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
    jLabel1.setText("Resultados");
    pnlTitulo.add(jLabel1, "card2");

    pnlTop.add(pnlTitulo);

    pnlSelecaoCargo.setBackground(new java.awt.Color(0, 51, 51));
    pnlSelecaoCargo.setBorder(javax.swing.BorderFactory.createMatteBorder(1, 0, 1, 0, new java.awt.Color(255, 255, 255)));
    pnlSelecaoCargo.setToolTipText("");
    pnlSelecaoCargo.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.LEFT, 15, 5));

    jLabel2.setFont(new java.awt.Font("Segoe UI", 0, 14)); // NOI18N
    jLabel2.setForeground(new java.awt.Color(255, 255, 255));
    jLabel2.setText("Cargo");
    jLabel2.setMaximumSize(new java.awt.Dimension(40, 25));
    jLabel2.setMinimumSize(new java.awt.Dimension(40, 25));
    jLabel2.setPreferredSize(new java.awt.Dimension(40, 25));
    pnlSelecaoCargo.add(jLabel2);

    cbxSelecaoCargo.setBackground(new java.awt.Color(0, 102, 102));
    cbxSelecaoCargo.setFont(new java.awt.Font("Segoe UI", 0, 14)); // NOI18N
    cbxSelecaoCargo.setForeground(new java.awt.Color(255, 255, 255));
    cbxSelecaoCargo.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Selecione um Cargo" }));
    cbxSelecaoCargo.setPreferredSize(new java.awt.Dimension(200, 25));
    cbxSelecaoCargo.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        cbxSelecaoCargoActionPerformed(evt);
      }
    });
    pnlSelecaoCargo.add(cbxSelecaoCargo);

    pnlTop.add(pnlSelecaoCargo);

    pnlMain.add(pnlTop, java.awt.BorderLayout.NORTH);

    pnlCenter.setBackground(new java.awt.Color(0, 51, 51));
    pnlCenter.setLayout(new java.awt.BorderLayout());

    pnlVotacaoTop.setBackground(new java.awt.Color(0, 51, 51));
    pnlVotacaoTop.setMinimumSize(new java.awt.Dimension(40, 60));
    pnlVotacaoTop.setPreferredSize(new java.awt.Dimension(40, 60));

    lblTituloCargo.setFont(new java.awt.Font("Segoe UI", 0, 18)); // NOI18N
    lblTituloCargo.setForeground(new java.awt.Color(255, 255, 255));
    lblTituloCargo.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
    lblTituloCargo.setText("lblTituloCargo");

    javax.swing.GroupLayout pnlVotacaoTopLayout = new javax.swing.GroupLayout(pnlVotacaoTop);
    pnlVotacaoTop.setLayout(pnlVotacaoTopLayout);
    pnlVotacaoTopLayout.setHorizontalGroup(
      pnlVotacaoTopLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addGap(0, 1033, Short.MAX_VALUE)
      .addGroup(pnlVotacaoTopLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGroup(pnlVotacaoTopLayout.createSequentialGroup()
          .addGap(0, 69, Short.MAX_VALUE)
          .addComponent(lblTituloCargo, javax.swing.GroupLayout.PREFERRED_SIZE, 790, javax.swing.GroupLayout.PREFERRED_SIZE)
          .addGap(0, 69, Short.MAX_VALUE)))
    );
    pnlVotacaoTopLayout.setVerticalGroup(
      pnlVotacaoTopLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addGap(0, 60, Short.MAX_VALUE)
      .addGroup(pnlVotacaoTopLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGroup(pnlVotacaoTopLayout.createSequentialGroup()
          .addGap(0, 0, Short.MAX_VALUE)
          .addComponent(lblTituloCargo, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE)
          .addGap(0, 0, Short.MAX_VALUE)))
    );

    pnlCenter.add(pnlVotacaoTop, java.awt.BorderLayout.NORTH);

    pnlVotacaoLeft.setBackground(new java.awt.Color(0, 51, 51));
    pnlVotacaoLeft.setMinimumSize(new java.awt.Dimension(200, 200));
    pnlVotacaoLeft.setName(""); // NOI18N
    pnlVotacaoLeft.setPreferredSize(new java.awt.Dimension(200, 200));
    pnlVotacaoLeft.setLayout(new java.awt.BorderLayout());

    pnlVotos.setBackground(new java.awt.Color(0, 51, 51));
    pnlVotos.setBorder(javax.swing.BorderFactory.createMatteBorder(1, 0, 0, 0, new java.awt.Color(255, 255, 255)));
    pnlVotos.setMinimumSize(new java.awt.Dimension(50, 50));
    pnlVotos.setPreferredSize(new java.awt.Dimension(50, 50));
    pnlVotos.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

    jLabel3.setFont(new java.awt.Font("Segoe UI", 1, 18)); // NOI18N
    jLabel3.setForeground(new java.awt.Color(255, 255, 255));
    jLabel3.setText("Votos");
    pnlVotos.add(jLabel3, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 0, 50, 50));

    lblTotalVotos.setFont(new java.awt.Font("Segoe UI", 1, 18)); // NOI18N
    lblTotalVotos.setForeground(new java.awt.Color(255, 255, 255));
    lblTotalVotos.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
    lblTotalVotos.setText("999.999.999");
    pnlVotos.add(lblTotalVotos, new org.netbeans.lib.awtextra.AbsoluteConstraints(70, 0, 120, 50));

    pnlVotacaoLeft.add(pnlVotos, java.awt.BorderLayout.NORTH);
    pnlVotos.getAccessibleContext().setAccessibleName("");

    pnlDetalheVotos.setBackground(new java.awt.Color(0, 51, 51));
    pnlDetalheVotos.setLayout(new java.awt.GridLayout(10, 0, 10, 0));

    jLabel4.setFont(new java.awt.Font("Segoe UI", 1, 18)); // NOI18N
    jLabel4.setForeground(new java.awt.Color(255, 255, 255));
    jLabel4.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
    jLabel4.setText("Brancos");
    jLabel4.setBorder(javax.swing.BorderFactory.createMatteBorder(1, 0, 0, 0, new java.awt.Color(255, 255, 255)));
    pnlDetalheVotos.add(jLabel4);

    pnlInfoVotosBrancos.setBackground(new java.awt.Color(0, 51, 51));
    pnlInfoVotosBrancos.setLayout(new java.awt.GridLayout(1, 0, 10, 0));

    lblQntdBrancos.setFont(new java.awt.Font("Segoe UI", 0, 18)); // NOI18N
    lblQntdBrancos.setForeground(new java.awt.Color(255, 255, 255));
    lblQntdBrancos.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
    lblQntdBrancos.setText("999.999.999");
    pnlInfoVotosBrancos.add(lblQntdBrancos);

    lblPercentBrancos.setFont(new java.awt.Font("Segoe UI", 0, 18)); // NOI18N
    lblPercentBrancos.setForeground(new java.awt.Color(255, 255, 255));
    lblPercentBrancos.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
    lblPercentBrancos.setText("(99,99%)");
    pnlInfoVotosBrancos.add(lblPercentBrancos);

    pnlDetalheVotos.add(pnlInfoVotosBrancos);

    jLabel7.setFont(new java.awt.Font("Segoe UI", 1, 18)); // NOI18N
    jLabel7.setForeground(new java.awt.Color(255, 255, 255));
    jLabel7.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
    jLabel7.setText("Nulos");
    jLabel7.setBorder(javax.swing.BorderFactory.createMatteBorder(1, 0, 0, 0, new java.awt.Color(255, 255, 255)));
    pnlDetalheVotos.add(jLabel7);

    pnlInfoVotosNulos.setBackground(new java.awt.Color(0, 51, 51));
    pnlInfoVotosNulos.setLayout(new java.awt.GridLayout(1, 0, 10, 0));

    lblQntdNulos.setFont(new java.awt.Font("Segoe UI", 0, 18)); // NOI18N
    lblQntdNulos.setForeground(new java.awt.Color(255, 255, 255));
    lblQntdNulos.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
    lblQntdNulos.setText("999.999.999");
    pnlInfoVotosNulos.add(lblQntdNulos);

    lblPercentNulos.setFont(new java.awt.Font("Segoe UI", 0, 18)); // NOI18N
    lblPercentNulos.setForeground(new java.awt.Color(255, 255, 255));
    lblPercentNulos.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
    lblPercentNulos.setText("(99,99%)");
    pnlInfoVotosNulos.add(lblPercentNulos);

    pnlDetalheVotos.add(pnlInfoVotosNulos);

    jLabel5.setFont(new java.awt.Font("Segoe UI", 1, 18)); // NOI18N
    jLabel5.setForeground(new java.awt.Color(255, 255, 255));
    jLabel5.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
    jLabel5.setText("Votos Válidos");
    jLabel5.setBorder(javax.swing.BorderFactory.createMatteBorder(1, 0, 0, 0, new java.awt.Color(255, 255, 255)));
    pnlDetalheVotos.add(jLabel5);

    pnlInfoVotosValidos.setBackground(new java.awt.Color(0, 51, 51));
    pnlInfoVotosValidos.setBorder(javax.swing.BorderFactory.createMatteBorder(0, 0, 1, 0, new java.awt.Color(255, 255, 255)));
    pnlInfoVotosValidos.setLayout(new java.awt.GridLayout(1, 0, 10, 0));

    lblQntdValidos.setFont(new java.awt.Font("Segoe UI", 0, 18)); // NOI18N
    lblQntdValidos.setForeground(new java.awt.Color(255, 255, 255));
    lblQntdValidos.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
    lblQntdValidos.setText("999.999.999");
    pnlInfoVotosValidos.add(lblQntdValidos);

    lblPercentValidos.setFont(new java.awt.Font("Segoe UI", 0, 18)); // NOI18N
    lblPercentValidos.setForeground(new java.awt.Color(255, 255, 255));
    lblPercentValidos.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
    lblPercentValidos.setText("(99,99%)");
    pnlInfoVotosValidos.add(lblPercentValidos);

    pnlDetalheVotos.add(pnlInfoVotosValidos);

    pnlVotacaoLeft.add(pnlDetalheVotos, java.awt.BorderLayout.CENTER);

    pnlCenter.add(pnlVotacaoLeft, java.awt.BorderLayout.WEST);

    pnlVotacaoButton.setBackground(new java.awt.Color(0, 51, 51));
    pnlVotacaoButton.setMinimumSize(new java.awt.Dimension(5, 5));
    pnlVotacaoButton.setPreferredSize(new java.awt.Dimension(5, 5));

    javax.swing.GroupLayout pnlVotacaoButtonLayout = new javax.swing.GroupLayout(pnlVotacaoButton);
    pnlVotacaoButton.setLayout(pnlVotacaoButtonLayout);
    pnlVotacaoButtonLayout.setHorizontalGroup(
      pnlVotacaoButtonLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addGap(0, 928, Short.MAX_VALUE)
    );
    pnlVotacaoButtonLayout.setVerticalGroup(
      pnlVotacaoButtonLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addGap(0, 5, Short.MAX_VALUE)
    );

    pnlCenter.add(pnlVotacaoButton, java.awt.BorderLayout.SOUTH);

    pnlVotacaoCenter.setBackground(new java.awt.Color(0, 51, 51));
    pnlVotacaoCenter.setLayout(new java.awt.CardLayout());

    jScrollPane1.setBackground(new java.awt.Color(0, 51, 51));
    jScrollPane1.setBorder(null);

    tableCandidatos.setBackground(new java.awt.Color(204, 255, 255));
    tableCandidatos.setFont(new java.awt.Font("Segoe UI", 1, 14)); // NOI18N
    tableCandidatos.setModel(new javax.swing.table.DefaultTableModel(
      new Object [][] {
        {null, null, null, null, null, null},
        {null, null, null, null, null, null}
      },
      new String [] {
        "Sequência", "Número", "Nome", "Partido", "Votos", "% Votos"
      }
    ) {
      boolean[] canEdit = new boolean [] {
        false, false, false, false, false, false
      };

      public boolean isCellEditable(int rowIndex, int columnIndex) {
        return canEdit [columnIndex];
      }
    });
    tableCandidatos.setMinimumSize(new java.awt.Dimension(450, 400));
    jScrollPane1.setViewportView(tableCandidatos);

    pnlVotacaoCenter.add(jScrollPane1, "card2");

    pnlCenter.add(pnlVotacaoCenter, java.awt.BorderLayout.CENTER);

    pnlVotacaoRight.setBackground(new java.awt.Color(0, 51, 51));
    pnlVotacaoRight.setMinimumSize(new java.awt.Dimension(5, 5));
    pnlVotacaoRight.setPreferredSize(new java.awt.Dimension(5, 5));

    javax.swing.GroupLayout pnlVotacaoRightLayout = new javax.swing.GroupLayout(pnlVotacaoRight);
    pnlVotacaoRight.setLayout(pnlVotacaoRightLayout);
    pnlVotacaoRightLayout.setHorizontalGroup(
      pnlVotacaoRightLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addGap(0, 5, Short.MAX_VALUE)
    );
    pnlVotacaoRightLayout.setVerticalGroup(
      pnlVotacaoRightLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addGap(0, 407, Short.MAX_VALUE)
    );

    pnlCenter.add(pnlVotacaoRight, java.awt.BorderLayout.EAST);

    pnlMain.add(pnlCenter, java.awt.BorderLayout.CENTER);

    pnlButton.setBackground(new java.awt.Color(0, 51, 51));
    pnlButton.setBorder(javax.swing.BorderFactory.createMatteBorder(1, 0, 0, 0, new java.awt.Color(255, 255, 255)));
    pnlButton.setMaximumSize(new java.awt.Dimension(30, 30));
    pnlButton.setMinimumSize(new java.awt.Dimension(30, 30));
    pnlButton.setPreferredSize(new java.awt.Dimension(30, 30));
    pnlButton.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.LEFT));

    lblStatus.setBackground(new java.awt.Color(255, 255, 255));
    lblStatus.setFont(new java.awt.Font("Segoe UI", 0, 12)); // NOI18N
    lblStatus.setForeground(new java.awt.Color(255, 255, 255));
    pnlButton.add(lblStatus);

    pnlMain.add(pnlButton, java.awt.BorderLayout.SOUTH);

    getContentPane().add(pnlMain, "card2");

    pack();
  }// </editor-fold>//GEN-END:initComponents

  private void cbxSelecaoCargoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cbxSelecaoCargoActionPerformed
    carregarDadosApuracao();
  }//GEN-LAST:event_cbxSelecaoCargoActionPerformed

  public static void main(String args[]) {
    Locale.setDefault(new Locale("pt", "BR"));
    
    java.awt.EventQueue.invokeLater(new Runnable() {
      public void run() {
        Apuracao dialog = new Apuracao(new javax.swing.JFrame(), true);
        dialog.addWindowListener(new java.awt.event.WindowAdapter() {
          @Override
          public void windowClosing(java.awt.event.WindowEvent e) {
            System.exit(0);
          }
        });
        dialog.setVisible(true);
      }
    });
  }

  // Variables declaration - do not modify//GEN-BEGIN:variables
  private javax.swing.JComboBox cbxSelecaoCargo;
  private javax.swing.JLabel jLabel1;
  private javax.swing.JLabel jLabel2;
  private javax.swing.JLabel jLabel3;
  private javax.swing.JLabel jLabel4;
  private javax.swing.JLabel jLabel5;
  private javax.swing.JLabel jLabel7;
  private javax.swing.JPanel jPanel5;
  private javax.swing.JScrollPane jScrollPane1;
  private javax.swing.JLabel lblPercentBrancos;
  private javax.swing.JLabel lblPercentNulos;
  private javax.swing.JLabel lblPercentValidos;
  private javax.swing.JLabel lblQntdBrancos;
  private javax.swing.JLabel lblQntdNulos;
  private javax.swing.JLabel lblQntdValidos;
  private javax.swing.JLabel lblStatus;
  private javax.swing.JLabel lblTituloCargo;
  private javax.swing.JLabel lblTotalVotos;
  private javax.swing.JPanel pnlButton;
  private javax.swing.JPanel pnlCenter;
  private javax.swing.JPanel pnlDetalheVotos;
  private javax.swing.JPanel pnlInfoVotosBrancos;
  private javax.swing.JPanel pnlInfoVotosNulos;
  private javax.swing.JPanel pnlInfoVotosValidos;
  private javax.swing.JPanel pnlMain;
  private javax.swing.JPanel pnlSelecaoCargo;
  private javax.swing.JPanel pnlTitulo;
  private javax.swing.JPanel pnlTop;
  private javax.swing.JPanel pnlVotacaoButton;
  private javax.swing.JPanel pnlVotacaoCenter;
  private javax.swing.JPanel pnlVotacaoLeft;
  private javax.swing.JPanel pnlVotacaoRight;
  private javax.swing.JPanel pnlVotacaoTop;
  private javax.swing.JPanel pnlVotos;
  private javax.swing.JTable tableCandidatos;
  // End of variables declaration//GEN-END:variables

  private void carregarDadosApuracao() {

    Cargo model = Cargo.consultar(cbxSelecaoCargo.getSelectedItem().toString());
    // se for na inicialisarção não mostra o panel com os detalhes da apuração
    if (model != null) {
      
      pnlCenter.setVisible(true);
      
      // Carregar dados na tabela
      atualizaTabel(model);
      
      // Carregar labels
        
      lblTotalVotos.setText(String.valueOf(Voto.totalVotosCargo(model)));
      lblQntdBrancos.setText(String.valueOf(Voto.allVotosBrancoCargo(model)));
      lblQntdNulos.setText(String.valueOf(Voto.allVotosNuloCargo(model)));
      lblQntdValidos.setText(String.valueOf(calcQntdVotosValidos(model)));
      
      lblPercentBrancos.setText("("+calcPercentVotosBrancos(model)+"%)");
      
      lblPercentNulos.setText(String.valueOf("("+calcPercentVotosNulos(model)+"%)"));
      
      lblPercentValidos.setText(String.valueOf("("+calcPercentVotosValidos(model)+"%)"));
      
      lblTituloCargo.setText(model.getNome());
    } else {
      pnlCenter.setVisible(false);
    }
  }

  private void iniciarTela() {

    for (Cargo listaCargos : cargos) {
      cbxSelecaoCargo.addItem(listaCargos.getNome());
    }
    pnlCenter.setVisible(false);
  }

  private void atualizaTabel(Cargo model) {
    
    DefaultTableModel modelTable ;
    ArrayList<Candidato>  listCand;        
    int sequencia = 1;
    // 
    modelTable = new DefaultTableModel();
    listCand   = Voto.executeApuracao(model);
    tableCandidatos.setDefaultEditor(Object.class, null);
    //
    modelTable.addColumn("Sequência");
    modelTable.addColumn("Número");
    modelTable.addColumn("Nome");
    modelTable.addColumn("Partido");
    modelTable.addColumn("Votos");
    modelTable.addColumn("% Válidos"); 
    //       
    for (Candidato cand: listCand) {     
      modelTable.addRow(new Object[] {sequencia,
                       cand.getNumeroCandidato(),
                       cand.getNome(),
                       cand.getPartido(),
                       cand.getQtdeVotos(),
                       df.format((double)cand.getQtdeVotos() * 100 / calcQntdVotosValidos(model))+"%"});
      //      
      sequencia = sequencia+1;
    }
    tableCandidatos.setModel(modelTable);
  }
  
  private String calcPercentVotosBrancos(Cargo cargo) {
    return df.format((double) Voto.allVotosBrancoCargo(cargo) * 100 
                            / Voto.totalVotosCargo(cargo));
  }
  
  private String calcPercentVotosNulos(Cargo cargo) {
    return df.format((double) Voto.allVotosNuloCargo(cargo) * 100
                            / Voto.totalVotosCargo(cargo));
  }
  
  private String calcPercentVotosValidos(Cargo cargo) {
    return df.format((double)(calcQntdVotosValidos(cargo)) * 100
                            / Voto.totalVotosCargo(cargo));
  }
  
  private int calcQntdVotosValidos(Cargo cargo) {
    return Voto.totalVotosCargo(cargo) 
         - Voto.allVotosBrancoCargo(cargo)
         - Voto.allVotosNuloCargo(cargo);
  }
  
}